﻿

////////////////////相关常量/////////////////////////////////////

var AniObj=null;//动画作品实体
var PageSize=6;//分页中每页记录条数
var MaxUploadFileNums=5;//最大上传数
var UploadActionPath=SBasePath+"/action/upload/";//上传路径
var ImagePath=SBasePath+"/images/manage/";//图片路径
var ProductSNO=0;//作品ID
var CurrentAuthorArr=new Array();//作者数组
var CurrentMaterialArr=new Array();//素材数组
var CurrentActorArr=new Array();//形象数组
var CurrentActorImageArr=new Array();//形象图片数组
var _mDebug=false;//调试标志位


var ActorFlashArr=new Array('.swf');//flash类型
var ActoMediaArr=new Array('.avi','.wma','.wmv','.mp3','.wav','.asf','.au','.w3u','.mpeg','.midi','.aiff');//视频类型 
var ActorImageArr=new Array('.jpg','.gif','.png','.bmp');//图片类型
var MapAllRecord='0';//所有记录
var MapPageRecord='1';//n-1条记录

var MaxImgSize=1; //1M

var MaxFlashSize=1;//10M

var MaxMediaSize=50;//50M;

 var MaxSize=0;
////////////////////页面加载函数/////////////////////////////

//页面加载函数

Event.observe(window,'load',LoadPage);

function  LoadPage()
{

    ShowAniUploadForm();

};

////////////////////生成页面/////////////////////////////////

//生成作品上传表单
var AniProgressWindow;
function ShowAniUploadForm()
{
    //var str="<div class='data2'><h4><a href='#' id='titleInfo'>上传作品</a></h4></div>";
    var str=' <form name="AniUpForm" id="AniUpForm" action="'+UploadActionPath+'EditorUpLoadResult.aspx"; method="post" enctype="multipart/form-data" target="Anitargethidenfram">';
    str+='    <table id="anifiletable"></table>';
    str+='    <input type="file" value="" name="anifile" id="anifile" size="37" style="width:300;">';
    str+='    <input class="magupload" onclick="AniStartUpload(\'AniUpForm\');" type="button" name="AniSubmitButton" id="AniSubmitButton" value="上传">';    
    //str+='     &nbsp;&nbsp;&nbsp;<a id="AniCancelButton" style="display:none" href="javascript: CancelUploadFromMainWindow(\'AniCancelButton\','+AniProgressWindow+');"';
    //str+='       style="visibility: hidden;"><img alt="Cancel uploading" width="89" style="display:none" height="22" border="0" src="'+ImagePath+'cancelbutton.gif"></a>';
    //str+="  <p class='maguploadts'>提示：你可以在上传的过程填写其他基本信息</p>"; 
    str+='<div id="Aniprogressout"></div>';
    str+=' <div id="AniUploadResultMsg"></div>';
    str+=' </form>';
    str+='<div id="AniVideoList">';
    str+='</div>';
    if(_mDebug)
    {
        str+='<iframe id="Anitargethidenfram" name="Anitargethidenfram" frameborder="0" height="200" width="400" visible="false"></iframe>'; 
    }
    else
    {
        str+='<iframe id="Anitargethidenfram" name="Anitargethidenfram" frameborder="0" height="0" width="0" visible="false"></iframe>';   
    }

    $("AniUploadDiv").innerHTML=str;
}



//////////////////////////作品上传相关///////////////////////////////////////
function CheckFileSize(strFileName,MaxSize){
try
{
var objStream = new ActiveXObject("ADODB.Stream");
if(objStream==null)
return false;
objStream.Type = 1;
objStream.Open();
objStream.LoadFromFile(strFileName);
alert(objStream.Size);
if(Math.round(objStream.Size/1024,2)>MaxSize)
{alert ("您选择的文件为 "+Math.round(objStream.Size/1024,2)+" KB　\n超过了程序"+MaxSize+" KB 的限制！");
document.form1.reset();
return false;
}
}
catch(e)
{
return true;
}
}

var CheckTime=0;
var EditorFileChecked=function(size)
{
    if(CheckTime==0)
    {       
        alert(Math.round(size/1024,2 )+"  "+MaxSize);
        if(Math.round(size/1024) > MaxSize)
        {
            CancelUploadFromProgress('AniCancelButton');
            alert("您所选择的文件超出系统的限制大小"+MaxSize+"KB");
        }
        
    }
}
function chkFileValid()
{  
    var AniUpForm=$("AniUpForm");
    var Url=AniUpForm.anifile.value;
    var name=Url.substring(Url.lastIndexOf('.'));
    if(name=="")
    {
        alert("您还没有选择任何文件");
        return false;
    }
   var tempArr=new Array(); 
  
    if(window.location.pathname.indexOf('flash')!=-1)
    {
         tempArr=ActorFlashArr;
         MaxSize=MaxFlashSize*1024;
    }
    if(window.location.pathname.indexOf('image')!=-1)
    {
         tempArr=ActorImageArr;
         MaxSize=MaxImgSize*1024;
    }
    if(window.location.pathname.indexOf('media')!=-1)
    {
         tempArr=ActoMediaArr;
         MaxSize=MaxMediaSize*1024;
    }
         
 // alert(tempArr);

    for(var i=0;i<tempArr.length;i++)
    {
        if(tempArr[i].toLowerCase()==name.toLowerCase())
        {           
            return CheckFileSize(Url,MaxSize);
        }
    }
    alert("文件类型错误");
    return false;
}

//开始上传作品
function AniStartUpload(formObj)
{
    //window.location);
    if(chkFileValid())
    {
	if(typeof(formObj)=="string")
		formObj = document.getElementById(formObj);
//	var CancelButton = document.getElementById("AniCancelButton");
//	if(CancelButton && PowUploadCanCancel())
//		CancelButton.style.visibility = "visible";
	var uniqueID = Math.floor(Math.random() * 10000000) + (new Date()).getTime() % 1000000000;
	AniProgressWindow = ShowAniProgressInFrame(uniqueID, UploadActionPath+'EditorProgress.aspx', 400, 200);		
	theAniPos = formObj.action.indexOf("UploadID");
	if (theAniPos >= 1)
		formObj.action = formObj.action.substring(0, theAniPos-1);
	if(formObj.action.indexOf("?")==-1)
		formObj.action += '?UploadID=' + uniqueID
	else
		formObj.action += '&UploadID=' + uniqueID;
    //formObj.action=UploadActionPath+'GetFileSize.aspx?UploadID=' + uniqueID;		
	formObj.submit();

	return true;
	}
}

//显示作品上传进度条
function ShowAniProgressInFrame(uniqueID, URL, width, height)
{
    var l = (screen.width - width) / 2;
	var t = (screen.height - height) / 2;
	var fullURL = URL;
	theAniPos = fullURL.indexOf("UploadID");
	if (theAniPos >= 1)
			fullURL = fullURL.substring(0, theAniPos-1);
	if(URL.indexOf("?")==-1)
		fullURL += '?UploadID=' + uniqueID;
	else
		fullURL += '&UploadID=' + uniqueID;
   $("Aniprogressout").innerHTML='<iframe id="Aniprogressframe" name="'+uniqueID+'" frameborder="0" height="'+height+'" width="'+width+'" visible="true" src="'+fullURL+'" SCROLLING="no"></iframe>';
	var newAniProgressWindow=$("Aniprogressframe");
	return newAniProgressWindow;
}

//上传作品完成
function AniUploadCommplete(fobjs)
{
    AniUpForm.anifile.value="";
    var str="";
    var filename="";
    if(fobjs!=null)
    {
        for(var i=0;i<fobjs.length;i++)
        {
            str+=fobjs[i].FileName;
            if(fobjs[i].FileName!="")
            {
                filename=fobjs[i].FileName;
            }
        }
     }

    $('txtUrl_hide').value=WebBasePath+str.strip();//修改路径 上传
    $("AniUploadResultMsg").innerHTML="文件成功上传名称为:<br>"+str; 

    $("Aniprogressframe").src="";
    $("Aniprogressframe").style.display ="none";
  //$("AniCancelButton").style.display ="none";

}









